<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class MediaBrowserImage extends sfImage
{
  public function saveAs($filename, $mime='', $name='', $folder='')
  {
    $copy = parent::saveAs($filename, $mime);
    $gallery = new Gallery();
    $gallery->setFilename($name);
    $gallery->setFolder($folder);
    $gallery->setCreatedAt(date('Y-m-d H:i:s'));
    $gallery->setUpdatedAt(date('Y-m-d H:i:s'));
    $gallery->save();
    return $copy;
  }

  public static function saveToDb($name='', $folder='')
  {
    try {
      $gallery = new Gallery();
      $gallery->setFilename($name);
      $gallery->setFolder($folder);
      $gallery->setCreatedAt(date('Y-m-d H:i:s'));
      $gallery->setUpdatedAt(date('Y-m-d H:i:s'));
      $gallery->save();
      return;
    } catch (Exception $exc) {
      return '{"jsonrpc" : "2.0", "error" : {"code": 999, "message": "Failed to save to database."}, "id" : "id"}';
    }
  }
}
?>
